package com.qfedu.hello.spring.myfactory;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @auther asus
 * @date 2022/4/26 9:39
 * 自定义一个类创建MySQL的连接对象
 */
public class MyFactory implements FactoryBean<Connection> {
    @Override
    public Connection getObject() throws Exception {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/db2202", "root", "123456");
        return connection;
    }

    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }

    @Override
    public boolean isSingleton() {
        //这个连接对象是单例的，因为每次连接数据库的的时候都是一个新的对象
        return false;
    }
}
